var app=getApp();
var ux = require('../../../../lib/ux.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {    
    account:{},
    isShow:true,
    merchant: null,
    money:0,
    userInfo: {},
    actionaa: "/api/memberUser/memberGetsAccount.do",
    action: "/api/memberUser/getUserInfoData.do",
    qrCodeUrl: "/api/memberCoupon/smallProgramCode.do",
    submit: "{{submit}}"
  },
  /**
    * 生命周期函数--监听页面显示
    */
  onShow: function () {
     if(this.data.isShow){
       var self=this;
       this.setData({
         isShow: false,
         money: 0,
         userInfo: {},
       })
       var $this = this;
       ux.request(this.data.actionaa, {}, function (protocol) {
         $this.setData({
           account: protocol.data.account
         });
       }, true);
       var options={};
       ux.request(this.data.action, options, function (data) {
         self.setData({
           userInfo: data.data.userInfo,
           count: data.data.count,
           money: data.data.money
         })
       }, true);
       var ppaa = { banrdId: self.data.merchant }
       ux.request(self.data.qrCodeUrl, ppaa, function (protocol) {
         if (protocol.data.qrcode) {
           self.setData({
             qrcode: protocol.data.qrcode
           })
           self.downLoadImg(protocol.data.hb, 'hb');
           self.downLoadImg(protocol.data.qrcode, 'qrcode');
         }
       }, true);
     }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      isShow: true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var self = this;
    this.setData({
      merchant: wx.getStorageSync("banrdId")
    });
   
  },
  downLoadImg: function (netUrl, storageKeyUrl) {
    wx.getImageInfo({
      src: netUrl,    //请求的网络图片路径
      success: function (res) {
        //请求成功后将会生成一个本地路径即res.path,然后将该路径缓存到storageKeyUrl关键字中
        // wx.setStorageSync("token", data.data.token);
        wx.setStorage({
          key: storageKeyUrl,
          data: res.path,
        });

      }
    })
  },
  onForm:function(event){
	if(this.data.submit){
		  var $this = this;
		  var dataset = event.currentTarget.dataset;
		  ux.request(this.data.submit,detail.value,function(protocol){
				if(protocol.success){
					if(dataset.url){
						wx.redirectTo(dataset.url);
					}
				}
		  },true);
	 }
  },
  
  onTap:function(event){
	  var dataset = event.currentTarget.dataset;
	  var data = this.data;
	  if(dataset.key && dataset.val){
		  data[dataset.key] = dataset.val;
	  }
	  this.setData(data);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

 

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

 look: function () {
    wx.navigateTo({
      url: '/pages/protocol/fxPolicy',
    })
  },
  toast: function (params) {
    if (typeof (params) == "string") {
      params = { content: params };
    }
    this.setData({
      toast: params.content
    });
    var THIS = this;
    setTimeout(function () {
      THIS.setData({
        toast: false
      });
      if (params.complete) {
        params.complete();
      }
    }, params.time || 3000);
  },
  toHB:function(){
      wx.navigateTo({
        url: '/pages/member/tab3/distribution/poster',
      })
  },
  toHHR:function(){
    wx.navigateTo({
      url: '/pages/member/tab3/distribution/hhr',
    })
  },
  toAlipays:function(){
      wx.navigateTo({
        url: '/pages/member/tab3/distribution/getMoneyNow',
      })
    
  },
  toWechat: function () {
      wx.navigateTo({
        url: '/pages/member/tab3/distribution/wechatGetMoney',
      })
  }
})
